package cn.edu.njpi;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.text.Font;
import javafx.stage.Stage;

/**
 * @author 朱宗辉
 * @version V1.0
 * @Package cn.edu.njpi
 * @date 2022/5/11 8:38 PM
 */
public class Main extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        Button b1 = new Button("b1");
        b1.setLayoutX(100);
        b1.setLayoutY(100);
        b1.setPrefWidth(400);
        b1.setPrefHeight(200);
        b1.setFont(Font.font(40));
        b1.setOnAction(actionEvent -> System.out.println("单击事件"));
        b1.addEventHandler(MouseEvent.MOUSE_CLICKED, mouseEvent -> {
            System.out.println(mouseEvent.getButton().name());
            System.out.println("鼠标单击");
            if (mouseEvent.getClickCount() == 2 && mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
                System.out.println("双击事件");
            }
        });
        b1.setOnKeyPressed(keyEvent -> System.out.println("按下了： " + keyEvent.getCode().name()));
        b1.setOnKeyReleased(keyEvent -> System.out.println("释放了： " + keyEvent.getCode().name()));
        Group root = new Group();
        root.getChildren().add(b1);
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.setTitle("javafx");
        stage.setHeight(800);
        stage.setWidth(800);
        stage.show();
    }
}